
namespace ShoppingCart.Business.Logic
{
	using System;
	using System.Collections.Generic;
    using System.Linq;
	using ShoppingCart.Business.Entity;
	using ShoppingCart.DataAccess;

	/// <summary>
	/// Represents the Manager of Distrito.
	/// </summary>
	[Serializable]
	public class DistritoManager : Singleton<DistritoManager>
	{
		#region Methods

		/// <summary>
		/// Selects a single record from the Distrito table.
		/// </summary>
		public Distrito Obtener(int idDistrito)
		{
			try
			{
				return DistritoData.Instancia.Obtener(idDistrito);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Selects all records from the Distrito table by a foreign key.
		/// </summary>
		public IList<Distrito> ListarPorIdProvincia(int idProvincia)
		{
			try
			{
				return DistritoData.Instancia.ListarPorIdProvincia(idProvincia);
			}
			catch (Exception) { throw; }
		}

        public IList<Distrito> ListarPorIdProvincia(int idProvincia, bool estado)
        {
            try
            {
                var distritos = DistritoData.Instancia.ListarPorIdProvincia(idProvincia);
                return distritos.Where(p => p.Estado == estado).ToList();
            }
            catch (Exception) { throw; }
        }

		/// <summary>
		/// Saves a record to the Distrito table.
		/// </summary>
		public int Agregar(Distrito distrito)
		{
			try
			{
				return DistritoData.Instancia.Agregar(distrito);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Updates a record in the Distrito table.
		/// </summary>
		public bool Modificar(Distrito distrito)
		{
			try
			{
				return DistritoData.Instancia.Modificar(distrito);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Deletes a record from the Distrito table by its primary key.
		/// </summary>
		public bool Eliminar(int idDistrito)
		{
			try
			{
				return DistritoData.Instancia.Eliminar(idDistrito);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Deletes a record from the Distrito table by a foreign key.
		/// </summary>
		public void EliminarPorIdProvincia(int idProvincia)
		{
			try
			{
				DistritoData.Instancia.EliminarPorIdProvincia(idProvincia);
			}
			catch (Exception) { throw; }
		}

		#endregion
	}
}
